package com.hzhr.iot.collect.service;

import com.hzhr.iot.collect.dao.CommandCountDao;
import com.hzhr.iot.collect.entity.CommandCountEntity;
import com.hzhr.iot.collect.queryModel.custom.CommandCountCustomQueryModel;
import com.hzhr.iot.core.util.HzhrDateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class CommandCountService {
    @Autowired
    CommandCountDao commandCountDao;

    public void addCount() {
        CommandCountCustomQueryModel commandCountCustomQueryModel = new CommandCountCustomQueryModel();
        commandCountCustomQueryModel.setEqual_date(HzhrDateUtil.getDayStartTime(new Date()));
        commandCountCustomQueryModel.setShow(true);
        CommandCountEntity commandcount = commandCountDao.selectEntity(commandCountCustomQueryModel);

        if (commandcount != null) {
            commandcount.setCount(commandcount.getCount() + 1);
            commandCountDao.update(commandcount);
        } else {
            commandcount = new CommandCountEntity();
            commandcount.setDate(new Date());
            commandcount.setCount(1);
            commandCountDao.insert(commandcount);
        }
    }

    public CommandCountEntity getCommandcountEntityByDayAndTransdir(Date date) {
        CommandCountCustomQueryModel commandCountCustomQueryModel = new CommandCountCustomQueryModel();
        commandCountCustomQueryModel.setEqual_date(HzhrDateUtil.getDayStartTime(date));
        commandCountCustomQueryModel.setShow(true);
        CommandCountEntity commandcount = commandCountDao.selectEntity(commandCountCustomQueryModel);

        return commandcount;
    }
}







































